package com.demo2do.fms.appointment.scheduler;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.demo2do.fms.appointment.service.AppointmentService;
import com.demo2do.fms.entity.report.DriverCostAppointment;
import com.demo2do.fms.entity.report.DriverMileageAppointment;
import com.demo2do.fms.entity.report.TransportRevenueAppointment;
import com.demo2do.fms.entity.report.VehicleMileageAppointment;

/**
 *
 * @author Ark
 *
 */
@Component("appointmentScheduler")
public class AppointmentScheduler {

    private static final Logger logger = LoggerFactory.getLogger(AppointmentScheduler.class);
    
    @Autowired
    private AppointmentService appointmentService;
    
    /**
     * handle vehicle mileage appointment
     */
    public void exportVehicleMileage() {
        
        logger.info("#exportVehicleMileage() - start...");
        
        List<VehicleMileageAppointment> appointments = appointmentService.listVehicleMileage();
        if (CollectionUtils.isEmpty(appointments)) {
            logger.info("#exportVehicleMileage() - appointments is empty...");
        }
        
        for (VehicleMileageAppointment appointment : appointments) {
            appointmentService.exportVehicleMileage(appointment);
        }
        
        logger.info("#exportVehicleMileage() - end...");
        
    }
    
    /**
     * handle driver mileage appointment
     */
    public void exportDriverMileage() {
        
        logger.info("#exportDriverMileage() - start...");
        
        List<DriverMileageAppointment> appointments = appointmentService.listDriverMileage();
        if (CollectionUtils.isEmpty(appointments)) {
            logger.info("#exportDriverMileage() - appointments is empty...");
        }
        
        for (DriverMileageAppointment appointment : appointments) {
            appointmentService.exportDriverMileage(appointment);
        }
        
        logger.info("#exportDriverMileage() - start...");
        
    }
    
    /**
     * handle transport revenue
     */
    public void exportTransportRevenue() {
        
        logger.info("#exportTransportRevenue() - start...");
        
        List<TransportRevenueAppointment> appointments = appointmentService.listTransportRevenue();
        if (CollectionUtils.isEmpty(appointments)) {
            logger.info("#exportTransportRevenue() - appointments is empty...");
        }
        
        for (TransportRevenueAppointment appointment : appointments) {
            appointmentService.exportTransportRevenue(appointment);
        }
        
        logger.info("#exportTransportRevenue() - start...");
        
    }
    
    /**
     * handle driver cost appointment
     */
    public void exportDriverCost() {
        
        logger.info("#exportDriverCost() - start...");
        
        List<DriverCostAppointment> appointments = appointmentService.listDriverCost();
        if (CollectionUtils.isEmpty(appointments)) {
            logger.info("#exportDriverCost() - appointments is empty...");
        }
        
        for (DriverCostAppointment appointment : appointments) {
            appointmentService.exportDriverCost(appointment);
        }
        
        logger.info("#exportDriverCost() - start...");
        
    }
    
}
